import React from 'react';

interface IInputInterceptProps {
  intercept: (onChange: any) => (value: any) => void;
  children: JSX.Element;
  onChange?: (value: any) => void;
  value?: any;
}

/**
 * 输入拦截器
 */
export default class InputIntercept extends React.Component<IInputInterceptProps> {
  render() {
    const { intercept, value, onChange, children } = this.props;
    return React.cloneElement(children, {
      value,
      onChange: intercept(onChange),
    });
  }
}